<template>
	<el-dialog :title="titleMap[mode]" v-model="visible" :width="1000" :close-on-press-escape="mode != 'show' ? false : true" destroy-on-close @closed="$emit('closed')" :close-on-click-modal="false">
        <el-container>
            <el-header>
                <div class="left-panel">
                    <div class="finish">
                        <div class="finishNum">合计:
                            <div class="text">{{ total_stock }}</div>
                        </div>
                    </div>
                </div>
                <div class="right-panel">
                    <div class="right-panel-search">
                        <el-input v-model="search.flower" placeholder="花型" clearable @blur="inputBlur('flower')" @keyup.enter="upsearch"></el-input>
                        <el-input v-model="search.color" placeholder="颜色" clearable @blur="inputBlur('color')" @keyup.enter="upsearch"></el-input>
                        <el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
                        <el-button type="primary" icon="el-icon-refresh" @click="refresh"></el-button>
                        <sc-export-button :auth="'stock_uninspect.export'" :apiObj="apiObj" :search="exportSearch" :selection="selection"></sc-export-button>
                    </div>
                </div>
            </el-header>
            <el-main class="nopadding"> 
                <scTable ref="table" :apiObj="apiObj" row-key="id" @selection-change="selectionChange" border @setExtend="setExtend" height="500" :params="query">
                    <el-table-column type="selection" width="50" align="center"></el-table-column>
                    <el-table-column label="花型" prop="flower" align="center"></el-table-column>
                    <el-table-column label="颜色" prop="color" align="center"></el-table-column>
                    <el-table-column label="库存(匹)" prop="curr_stock" align="center" width="120"></el-table-column>
                    <el-table-column label="操作" align="center" width="120">
                        <template #default="scope">
                            <div class="buttonFlex">
                                <el-button type="primary" size="small" @click="table_show(scope.row, scope.$index)">查看</el-button>
                            </div>
                        </template>
                    </el-table-column>
                </scTable>
            </el-main>
        </el-container>
		<template #footer>
			<el-button @click="visible = false">取 消</el-button>
		</template>
	</el-dialog>
    <show-house v-if="dialog.house" ref="houseDialog" @success="handleSuccess" @closed="dialog.house = false" :query="{stock_id: stock_id}"></show-house>
</template>

<script>
import showHouse from './showHouse.vue'
export default {
  components: { showHouse },
    props:{
        query: { type: Object, default: () => ({}) },
    },
	emits: ['success', 'closed'],
	data() {
		return {
			mode: "add",
			titleMap: {
				add: '新增',
				edit: '编辑',
				show: '查看'
			},
			visible: false,
			apiObj: this.$API.ware.ware.stock_uninspect.list,
            id:"",
            search: {
                flower: null,
                color: null,
            },
            exportSearch: {},
            total_stock: 0,
            dialog: {
                house: false,
            },
            stock_id: "",
			selection: [],
		}
	},
	mounted() {
        this.exportSearch = {
            ...this.query
        }
	},
	methods: {
        setExtend(data) {
            this.total_stock = data.curr_stock_sum
        },
		//显示
		open(mode = 'add') {
			this.mode = mode;
			this.visible = true;
			return this
		},
        //搜索
		upsearch() {
			this.$refs.table.upData(this.search)
		},
        refresh() {
            for (const key in this.search) {
                this.search[key] = null;
            }
            this.$refs.table.upData(this.search)
        },
        inputBlur(name){
            this.exportSearch[name] = this.search[name];
        },
        //查看
		table_show(row) {
            this.stock_id = row.id
			this.dialog.house = true
			this.$nextTick(() => {
				this.$refs.houseDialog.open('show')
			})
		},
        selectionChange(selection) {
			this.selection = selection;
		},
	}
}
</script>

<style></style>
